<template>
    <div>
        <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="用户名">
      <el-input v-model="form.name" />
    </el-form-item>
    <el-form-item label="地址">
 
        <el-cascader
      size="large"
      :options="pcaTextArr"
      v-model="addressArray"
      >
    </el-cascader>
    </el-form-item>
   <el-form-item label="部门">
    <el-select v-model="form.departmentId" placeholder="请选择部门" style="width: 150px;">
        <el-option label="无" :value="0" />
        <el-option label="生产部" :value="1" />
         <el-option label="采购部" :value="2" />
         <el-option label="管理部" :value="3" />
 <el-option label="销售部" :value="4" />
 <el-option label="大客户部" :value="5" />
      </el-select>
     
       </el-form-item>
       <el-form-item label="职位">
      <el-radio-group v-model="form.powerId">
        <el-radio :value="0">员工</el-radio>
        <el-radio :value="1">部门领导</el-radio>
        <el-radio :value="2">总负责人</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="form.sex">
        <el-radio :value="true">男</el-radio>
        <el-radio :value="false">女</el-radio>
      </el-radio-group>
    </el-form-item>
      <el-form-item label="详细地址">
      <el-input v-model="form.address" />
    </el-form-item>
     <el-form-item>
      <el-button type="primary" @click="adduser()">添加</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>

    </div>
</template>
<script setup lang="ts">
import { ref,reactive, onMounted } from 'vue';
import {axios} from '@/axios/axiosHelp'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'
import {
  provinceAndCityData,
  pcTextArr,
  regionData,
  pcaTextArr,
  codeToText,
} from "element-china-area-data";
const router = useRouter()
const form = reactive({
  "name": "",
  "pass": "123456",
  "sex": true,
  "province": "",
  "city": "",
  "county": "",
  "departmentId": "",
  "address": "",
  "createUser": "admin",
  "updateUser": "",
  "powerId": null
})
const addressArray=ref([])
const adduser = () => {
  if (form.name=="") {
    ElMessage.error("用户名不得为空")
    return;
  }
  form.province = addressArray.value[0]
  form.city = addressArray.value[1]
  form.county = addressArray.value[2]
  console.log(form)
    axios.post("https://localhost:7181/api/User/AddUser",form).then((res) => {
        if (res.data.code==100) {
            ElMessage.success(res.data.msg)
            router.push('/GetUser');
        } else {
            ElMessage.error(res.data.msg)
        }

    })
}


</script>

<style scoped>

</style>